<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>

    <template id="my-app">
      <div>
        <h2>{{info.name}}</h2>
        <button @click="changeInfo">changeInfo</button>
        <button @click="changeInfoName">changeInfoName</button>
      </div>
    </template>

    <script src="../vue/vue.js"></script>
    <script>
        const App = {
            template: '#my-app',
            data() {
                return {
                    info: {name: 'leon', age: 18}
                }
            },
            watch: {
                // info(newValue, oldValue) {
                //     console.log(newValue, oldValue);
                // }

                // 深度监听/立即执行
                info: {
                    handler: function(newValue, oldValue) {
                        console.log(newValue, oldValue);
                    },
                    deep: true,
                    immediate: true
                }
            },
            methods: {
                changeInfo() {
                    this.info = {name: 'leon'}
                },
                // 这个改变是监听不到的
                changeInfoName() {
                    this.info.name = {name: 'leon'}
                }
            }
        }

        Vue.createApp(App).mount('#app');
    </script>
</body>
</html>